<template>
	<view class="goods_list">
		<goodsList :goods="goods"></goodsList>
		<view class="isOver" v-if="flag">----我是有底线的----</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods_list/goods_list'
	export default {
	    components: {
	      'goodsList': goodsList
		},
		data() {
			return {
				pageindex: 1,
				goods: [],
				flag: false
			}
		},
		methods: {
			//获取商品列表的数据
			async getGoodsList(callBack){
			    const res = await this.$myRequest({
			        url: '/api/getgoods?pageindex=' + this.pageindex,
			    })
				// if(res.data.message.length < 10){
				// 	this.flag = true
				// }
				this.goods = [...this.goods,...res.data.message]
				callBack && callBack()
			}
		},
		onReachBottom(){
			if(this.goods.length < this.pageindex * 10){
				return this.flag = true
			} else{
				this.pageindex ++;
			}
			this.getGoodsList();
		},
		onPullDownRefresh(){
	      this.pageindex = 1;
	      this.goods = [];
	      this.flag = false;
	      setTimeout(() =>{
			this.getGoodsList(() => {
			    uni.stopPullDownRefresh()
			})
		  },1000)
		},
		onLoad(){
	        this.getGoodsList()
		}
	}
</script>

<style lang="scss">
	.goods_list{
		background-color: #eee;
	}
	.isOver{
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 28rpx;
	}
</style>
